package com.plwf.lake.service.impl;

import com.plwf.lake.entity.Coach;
import com.plwf.lake.mapper.CoachMapper;
import com.plwf.lake.service.CoachService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
@Service
public class CoachServiceImpl implements CoachService {
    @Resource
    private CoachMapper mapper;

    @Override
    public List<Coach> query(Map<String, Object> map) {
        return this.mapper.select(map);
    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean save(Coach coach) {
        if(coach.getCoaId()!=null){
            return this.mapper.update(coach);
        }else{
            return this.mapper.insert(coach);
        }

    }

    @Override
    @Transactional(propagation= Propagation.REQUIRED,rollbackFor=SQLException.class)
    public boolean remove(Integer coaId) {
        return this.mapper.delete(coaId);
    }

    @Override
    public Coach find(Integer coaId) {
        return this.mapper.selectOne(coaId);
    }

    @Override
    public boolean enable(Integer id, Integer status) {
        Coach coach = new Coach();
        coach.setCoaId(id);
        coach.setStatus(status);
        return this.mapper.enable(coach);
    }

    @Override
    public boolean updateImage(Coach coach) {
        return this.mapper.updateImage(coach);
    }

    @Override
    public List<Coach> queryAll() {
        return this.mapper.selectAll();
    }

    @Override
    public Coach login(Coach bean) {
        return this.mapper.login(bean);
    }

    @Override
    public Integer maxId() {
        return this.mapper.maxId();
    }
}
